package gui;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

import student.Student;

@SuppressWarnings("serial")
public class TableModel_students extends AbstractTableModel implements
		TableModel
{

	private ArrayList<Student> students_list = new ArrayList<Student>();

	private String[] columName = new String[] { "Vorname", "Nachname",
			"MatrNr.", "Fachbereich", "e-Mail", "Rolle" };

	public TableModel_students(ArrayList<Student> students)
	{
		students_list = students;
	}

	public TableModel_students()
	{

	}

	@Override
	public int getColumnCount()
	{
		return 5;
	}

	@Override
	public int getRowCount()
	{
		return students_list.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		for (int i = 0; i < students_list.size(); i++)
		{

			switch (columnIndex)
			{
			case 0:
				return students_list.get(rowIndex).getFirstName();
			case 1:
				return students_list.get(rowIndex).getLastName();
			case 2:
				return students_list.get(rowIndex).getMatrNr();
			case 3:
				return students_list.get(rowIndex).getBranch();
			case 4:
				return students_list.get(rowIndex).getMail();
			}
		}
		return null;
	}

	@Override
	public String getColumnName(int column)
	{
		return columName[column];
	}
}
